{include file="admin@public/header" /}

<style>
	#matchCon {
		width: 160px;
	}

	.url-box {
		padding: 5px 10px;
		line-height: 26px;
		cursor: pointer;
	}

	.url-box a {
		margin-right: 5px;
	}
	.ui-jqgrid .ui-jqgrid-bdiv .line{margin: 3px -5px;}

	.ui-jqgrid tr.ui-row-ltr td {
		position: relative;
	}
	.number_sku {
		padding: 13px 13px 0 0;
		position: absolute;
		right: 10px;
		top: 13px;
	}

	.expand-operate {
		position: absolute;
		left: 8px;
		top: 3px;
	}

	.add {
		background: #fff url("/public/static/admin/css/img/number_sku.png") no-repeat;
	}

	.plus {
		background: #fff url("/public/static/admin/css/img/number_sku.png") no-repeat 0 -13px;
		top: 5px;
	}
</style>


<div class="bill-ser-top">
	<ul class="ul-inline cf">
		<li>
			<input type="text" id="matchCon" class="ui-input ui-input-ph" placeholder="请输入单据号或客户名或备注"
				style="width: 190px;">
		</li>
		<li>
			<label>日期:</label>
			<input type="date" id="datew" class="ui-input " value="{$mon_start}" style="width: 125px;">
			<i>-</i>
			<input type="date" id="dateo" class="ui-input " value="{$today}" style="width: 125px;">
		</li>

		
		<li><a class="mrb more ui-btn" id="moreCon"  onclick="heightSe('/admin/basic/hight_search.html?o_type={$o_type}','高级搜索','815px','460px')">高级搜索</a><a class="ui-btn mrb ui-btn-search" id="search">查询</a></li>
		<!-- <li class="url-box" id="openUrl"><a href="https://club.kingdee.com/club/newclub/school/course?product_id=7&amp;cid=1548#pid=5704" target="_blank" class="video-icon"></a>购货订单查询</li> -->
	</ul>
</div>
<div class="wrapper btc">
	<div class="bill-ser-botm cf">
		<div class="ui-config-box">
			<span id="config" class="ui-config"><a href="#" class="ui-icon-config-new"></a>列设置</span>
		</div>
		<div class="fr">
			<a class="ui-btn-bill ui-btn-add" id="add" onclick="addPage('/store/move/add.html','storage','调拨单')">新增</a>

			<div class="ui-btn-menu ml10">
				<a class="ui-btn-bill ui-btn-hl menu-btn mrb" style="width: 40px;padding-right: 14px;" href="#"
					id="audit">审核<b></b></a>
				<div class="con hl more-operate-con" style="margin-left: 0px;font-size: 14px;width: 55px;padding: 6px;">
					<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
						<li><a href="#" id="reAudit">反审核</a></li>
					</ul>
				</div>
			</div>
			<div class="ui-btn-menu ml10">
				<a class="ui-btn-bill ui-btn-hl menu-btn mrb" href="#" id="print" target="_blank"
					href="javascript:void(0);">打印<b></b></a>
				<div class="con hl more-operate-con" style="margin-left: 0px;font-size: 14px;width: 54px;padding: 3px;">
					<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
						<li style="padding-left: 8px;"><a href="#" id="printSet" href="javascript:void(0);">设置</a></li>
					</ul>
				</div>
			</div>
			<div class="ui-btn-menu ml10">
				<a class="ui-btn-bill ui-btn-hl menu-btn mrb" style="width: 40px;padding-right: 7px;" href="#"
					id="import"  href="javascript:void(0);">导入<b></b></a>
				<div class="con hl more-operate-con" style="margin-left: 0px;font-size: 14px;width: 54px;padding: 3px;">
					<ul class="more-operate cf" style="border-style:dashed; border-width:1px; border-color:#ccc;">
						<li style="padding-left: 8px;"><a href="#" id="export" 
								href="javascript:void(0);">导出</a></li>
					</ul>
				</div>
			</div>

			<a href="#" class="ui-btn-bill ui-btn-hl ml10" id="btn-batchDel">删除</a>
		</div>
	</div>
	<div class="grid-wrap">
		<table id="grid">
		</table>
		<div id="page"></div>
	</div>
</div>


<script type="text/javascript">
	$("#export").click(function () {
		var page = $('#grid').getGridParam('page'); // current page
	    var rows = $('#grid').getGridParam('rowNum'); // rows
	    var rowData = $("#grid").getRowData();
	    var rowid = '';
	    rowData.forEach(function(a,b,c){
	    	rowid += a['id']+' ';
	    })
		window.location.href = '/store/move/export?page='+page+'&rows='+rows+'&rowid='+rowid;
	})
	//$(function(){
	$(document).ready(function () {

		// 鼠标移入订单状态
		$("#filter-menu").hover(function () {
			$(this).addClass("ui-btn-menu-cur");
		}, function () {
			$(this).removeClass("ui-btn-menu-cur");
		});
		// 按钮移入移出
		$(".ui-btn-menu.ml10").hover(function () {
			$(this).addClass("ui-btn-menu-cur");
		}, function () {
			$(this).removeClass("ui-btn-menu-cur");
		});

		//function a(a, b, c) {
			// 	var d = '<div class="operating" data-id="' + c.id + '"><span class="ui-icon ui-icon-pencil" title="修改"></span><span class="ui-icon ui-icon-trash" title="删除"></span></div>';
			// 	return d
			// }
			function b(a) {
				//var b = a.join('<p class="line" />');
				var b = a.join('<p class="combineOrNot combineHeight line" style="display: block;    zoom: 1;height: 1px;font-size: 12px;line-height: 2;margin: 3px 2px;overflow:visible">');
				
				console.log(b);
				return b;
			}

			function  pipei(t, i, e) {
		                
		        if (1 == t.length) return t[0];
		        if (1 < t.length) {
		            for (var n = [], a = 0; a < t.length; a++) n[a] = 0 == a ? "<p class='combineHeight' style='margin-bottom: 10px;'>" + t[a] + '</p><span class="number_sku add"></span>': '<p class="combineOrNot combineHeight" style="margin-top: 10px;">' + t[a] + "</p>";
		                return n.join('<p class="line combineOrNot" />');
		            }
		        return t;
		    }
		

		
			

		//alert("1111");
		$("#grid").jqGrid({
			url: '/store/move/index.html?ajax=100',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			//width: Public.setGrid().w,
			//height: Public.setGrid().h,
			colNames: ["id","操作", "单据日期", "单据编号", "商品", "商品类别", "商品备注", "数量", "单位", "调出仓库", "调入仓库", "分录备注","制单人", "审核人", "备注", "打印次数","行高","订单状态"],
			colModel: [
				{ name: 'id', hidden:true },
				{ name: 'cz', width: 70, formatter: actions },
				{ name: 'time',width: 90, },
				{ name: 'sn' ,width: 100},
				{name: "goods_name",width: 200,formatter: goodsName},
				{name: "goods_type",width: 100,formatter: goodsType},
				{name: "goods_mark",width: 200,formatter: goodsMark},
				{name: "goods_num",width: 60,formatter: goodsNum},
				{name: "goods_dw",width: 60,formatter: goodsDw},
				{name: "goods_ck2",width: 80,formatter: goodsStoreOut},
				{name: "goods_ck1",width: 80,formatter: goodsStoreIn},
				{name: "goods_marks",width: 200,formatter: goodsMarks},
				// {name: "goods_name",width: 200,formatter: function(t, i, e) {return pipei(t, i, e);}},
				// {name: "goods_type",width: 100,formatter: function(t, i, e) {return pipei(t, i, e);}},
				// {name: "goods_mark",width: 200,formatter: function(t, i, e) {return pipei(t, i, e);}},
				// {name: "goods_num",width: 60,formatter: function(t, i, e) {return pipei(t, i, e);}},
				// {name: "goods_dw",width: 60,formatter: function(t, i, e) {return pipei(t, i, e);}},
				// {name: "goods_ck2",width: 80,formatter: function(t, i, e) {return pipei(t, i, e);}},
				// {name: "goods_ck1",width: 80,formatter: function(t, i, e) {return pipei(t, i, e);}},
				// {name: "goods_marks",width: 200,formatter: function(t, i, e) {return pipei(t, i, e);}},

				{ name: 'add_user' },
				{ name: 'shenhe_user' },
				{ name: 'mark' },
				{ name: 'print_number' },
				{name: "col_h",hidden: true},//行高
				{name: "zt",hidden: true},//订单状态
				

			],
			sortable: true,  //排序

			rowNum: 10,
			rowList: [10, 20, 30],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置
			multiselect:true,
			pgbuttons: true,//翻页按钮
			pagination: true,
			altRows: !0,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			cmTemplate: {
				sortable: !1,
				title: !1
			},

			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			},
			gridComplete: function () {
				var grid = $("#grid");
                var col_hs = grid.getCol('col_h',false);//获取某一列
                var ids = grid.getDataIDs();

                var rowDatas = grid.jqGrid("getRowData");//获取所有行的数据
              	//alert(col_hs);
                for (var i = 0; i < ids.length; i++) {
                	//设置行高
                    // grid.setRowData ( ids[i], false, {height: 40*col_hs[i]} );
                    var rowData = rowDatas[i];
                    if(rowData.zt=="0"){
                    	$("#"+ids[i]+ " td").css("color","#999999");
                    }
                }


				
			},

			
		});
	});

	function actions(cellvalue, options, rowObject) {
		return '<div class="operating"><span class="ui-icon ui-icon-pencil" onclick="addPage(\'/store/move/edit.html?move_id=' + rowObject.id + '\',\'storage\',\'调拨单\')">修改</span> <span class="ui-icon ui-icon-trash" onclick="del(' + rowObject.id + ')">删除</span></div>';
	}

	// 商品名称
	function goodsName(cellvalue, options, rowObject){
			var html = '<div id="childThing' + rowObject.id + '">\
			<p class="combineHeight pl25">'+ rowObject.goods_name[0] + '</p>';
			if(rowObject.goods_name.length>1){
				html += '<span class="number_sku add" id="number_sku' + rowObject.id + '" onclick="showHide(' + rowObject.id + ')"></span>';
			}
			for (let i = 1; i < rowObject.goods_name.length; i++) {
				const element = rowObject.goods_name[i];
				html += '<p class="line combineOrNot" style="display: none;"></p><p class="combineOrNot combineHeight pl25" style="display: none;">' + element + '</p>';
			}
			html += '</div >';
			return html;
		}


		// 商品类别
		function goodsType(cellvalue, options, rowObject){
			var html = '<div id="goodsType' + rowObject.id + '"><p class="combineHeight pl25">' + rowObject.goods_type[0] + '</p>'
			for (let i = 1; i < rowObject.goods_type.length; i++) {
				const element = rowObject.goods_type[i];
				html += '<p class="line combineOrNot" style="display: none;"></p><p class="combineOrNot combineHeight pl25" style="display: none;">' + element + '</p>';
			}
			html += '</div >';
			return html;
		}
		// 商品备注
		function goodsMark(cellvalue, options, rowObject){
			var html = '<div id="goodsMark' + rowObject.id + '"><p class="combineHeight pl25">' + rowObject.goods_mark[0] + '</p>'
			for (let i = 1; i < rowObject.goods_mark.length; i++) {
				var element = rowObject.goods_mark[i];
				if(element=="" || element==null){
					element="&nbsp;"
				}
				html += '<p class="line combineOrNot" style="display: none;"></p><p class="combineOrNot combineHeight pl25" style="display: none;">' + element + '</p>';
			}
			html += '</div >';
			return html;
		}
		// 商品数量
		function goodsNum(cellvalue, options, rowObject){
			var html = '<div id="goodsNum' + rowObject.id + '"><p class="combineHeight pl25">' + rowObject.goods_num[0] + '</p>'
			for (let i = 1; i < rowObject.goods_num.length; i++) {
				var element = rowObject.goods_num[i];
				if(element=="" || element==null){
					element="&nbsp;"
				}
				html += '<p class="line combineOrNot" style="display: none;"></p><p class="combineOrNot combineHeight pl25" style="display: none;">' + element + '</p>';
			}
			html += '</div >';
			return html;
		}
		// 商品单位
		function goodsDw(cellvalue, options, rowObject){
			var html = '<div id="goodsDw' + rowObject.id + '"><p class="combineHeight pl25">' + rowObject.goods_dw[0] + '</p>'
			for (let i = 1; i < rowObject.goods_dw.length; i++) {
				var element = rowObject.goods_dw[i];
				if(element=="" || element==null){
					element="&nbsp;"
				}
				html += '<p class="line combineOrNot" style="display: none;"></p><p class="combineOrNot combineHeight pl25" style="display: none;">' + element + '</p>';
			}
			html += '</div >';
			return html;
		}
		// 调出仓库
		function goodsStoreOut(cellvalue, options, rowObject){
			var html = '<div id="goodsStoreOut' + rowObject.id + '"><p class="combineHeight pl25">' + rowObject.goods_ck2[0] + '</p>'
			for (let i = 1; i < rowObject.goods_ck2.length; i++) {
				var element = rowObject.goods_ck2[i];
				if(element=="" || element==null){
					element="&nbsp;"
				}
				html += '<p class="line combineOrNot" style="display: none;"></p><p class="combineOrNot combineHeight pl25" style="display: none;">' + element + '</p>';
			}
			html += '</div >';
			return html;
		}
		// 调入仓库
		function goodsStoreIn(cellvalue, options, rowObject){
			var html = '<div id="goodsStoreIn' + rowObject.id + '"><p class="combineHeight pl25">' + rowObject.goods_ck1[0] + '</p>'
			for (let i = 1; i < rowObject.goods_ck1.length; i++) {
				var element = rowObject.goods_ck1[i];
				if(element=="" || element==null){
					element="&nbsp;"
				}
				html += '<p class="line combineOrNot" style="display: none;"></p><p class="combineOrNot combineHeight pl25" style="display: none;">' + element + '</p>';
			}
			html += '</div >';
			return html;
		}
		// 分录备注
		function goodsMarks(cellvalue, options, rowObject){
			var html = '<div id="goodsMarks' + rowObject.id + '"><p class="combineHeight pl25">' + rowObject.goods_marks[0] + '</p>'
			for (let i = 1; i < rowObject.goods_marks.length; i++) {
				var element = rowObject.goods_marks[i];
				if(element=="" || element==null){
					element="&nbsp;"
				}
				html += '<p class="line combineOrNot" style="display: none;"></p><p class="combineOrNot combineHeight pl25" style="display: none;">' + element + '</p>';
			}
			html += '</div >';
			return html;
		}

		// 列表点击显示隐藏
		function showHide(rid) {
			// console.log(rid);

			var open = $("#number_sku" + rid).hasClass("plus");
			// 判断是否展开子件详情
			if (open) {
				// 改变图标
				$("#number_sku" + rid).addClass("add").removeClass("plus");
				// 隐藏商品名称
				$("#childThing" + rid).find(".combineOrNot").hide();
				// 隐藏商品类别
				$("#goodsType" + rid).find(".combineOrNot").hide();
				// 隐藏商品备注
				$("#goodsMark" + rid).find(".combineOrNot").hide();
				// 隐藏商品数量
				$("#goodsNum" + rid).find(".combineOrNot").hide();
				// 隐藏商品单位
				$("#goodsDw" + rid).find(".combineOrNot").hide();
				// 隐藏调出仓库
				$("#goodsStoreOut" + rid).find(".combineOrNot").hide();
				// 隐藏调入仓库
				$("#goodsStoreIn" + rid).find(".combineOrNot").hide();
				// 隐藏分录备注
				$("#goodsMarks" + rid).find(".combineOrNot").hide();
			} else {
				$("#number_sku" + rid).addClass("plus").removeClass("add");
				$("#childThing" + rid).find(".combineOrNot").show();
				$("#goodsType" + rid).find(".combineOrNot").show();
				$("#goodsMark" + rid).find(".combineOrNot").show();
				$("#goodsNum" + rid).find(".combineOrNot").show();
				$("#goodsDw" + rid).find(".combineOrNot").show();
				$("#goodsStoreOut" + rid).find(".combineOrNot").show();
				$("#goodsStoreIn" + rid).find(".combineOrNot").show();
				$("#goodsMarks" + rid).find(".combineOrNot").show();
			}
		}
	//搜索
	$("#search").click(function () {

		var matchCon = $("#matchCon").val();
		var datew = $("#datew").val();
		var dateo = $("#dateo").val();

		$("#grid").jqGrid('setGridParam', {
	        datatype: 'json',
	        //发送数据 
	        postData: { 'ajax': '100', 'matchCon':matchCon,'datew':datew,'dateo':dateo,'search':0 },
	        page: 1
    	}).trigger("reloadGrid"); //重新载入

		//删除加载缓存	
		var postData = $("#grid").jqGrid("getGridParam", "postData");
	　　	$.each(postData, function (k, v) { 
	　　    delete postData[k];  
	　　});

	});
	// 高级搜索
	function heightSear(url, title, width, height){
		layer.open({
			type: 2,
			title: title,
			shadeClose: true,
			shade: 0.3,
			maxmin: true, //开启最大化最小化按钮
			btn: ['重置', '查询', '关闭'],
			area: [width, height],
			content: url,
			btn1: function (index, layero) {
				document.getElementById("layui-layer-iframe"+index).contentWindow.location.reload();
				return false;
			},
			btn2:function(index, layero){
				layer.close(index);

				var fromDate=layero.find("iframe")[0].contentWindow.$("#filter-fromDate").val();//高级搜索开始时间
				var toDate=layero.find("iframe")[0].contentWindow.$("#filter-toDate").val();//高级搜索结束时间
				var remarkCon=layero.find("iframe")[0].contentWindow.$("#remarkCon").val();//备注
				var storeOutId=layero.find("iframe")[0].contentWindow.$("#storeOutId").val();//调出厂库
				var storeInId=layero.find("iframe")[0].contentWindow.$("#storeInId").val();//调入厂库
				var usersCreatId=layero.find("iframe")[0].contentWindow.$("#usersCreatId").val();//制单人
				var goods_id=layero.find("iframe")[0].contentWindow.$("#goods_id").val();//商品
				var usersModifyId=layero.find("iframe")[0].contentWindow.$("#usersModifyId").val();//最后修改人
				var usersChecksId=layero.find("iframe")[0].contentWindow.$("#usersChecksId").val();//审核人
				var checkStatusId=layero.find("iframe")[0].contentWindow.$("#checkStatusId").val();//审核状态

				$("#grid").jqGrid('setGridParam', {
			        datatype: 'json',
			        postData: { 
			        	'ajax':'100',
			        	'search':'1',
						'fromDate':fromDate,
						'toDate':toDate,
						'remarkCon':remarkCon,
						'storeOutId':storeOutId,
						'storeInId':storeInId,
						'usersCreatId':usersCreatId,
						'usersModifyId':usersModifyId,
						'goods_id':goods_id,
						'usersChecksId':usersChecksId,
						'checkStatusId':checkStatusId
			        }, //发送数据 
			        page: 1
			    }).trigger("reloadGrid"); //重新载入
			    var postData = $("#grid").jqGrid("getGridParam", "postData");
			　　　　$.each(postData, function (k, v) { 
			　　　　　　delete postData[k];  
			　　　　});
				return false;
			},
			btn3:function(index, layero){
				layer.close(index);
				return false;
			},
			success: function (layero, index) {
	            //渲染按钮样式
				$(".layui-layer-btn .layui-layer-btn0").css({
					"background": "-webkit-gradient(linear,0 0,0 100%,from(#f2f2f2),to(#f4f4f4))",
					"float": "left",
					"color":"#555",
					"border":"1px solid #c1c1c1",
				});
				$(".layui-layer-btn .layui-layer-btn1").css({
					"background": "linear-gradient(to bottom,#4dc2e6 0,#38B3EB 100%)",
					"color":"#fff",
					"border":"1px solid #38B3EB"

				});
	        }
		});
	};

</script>

{include file="admin@public/footer" /}